<template>
    <div class="teaching-push-check">
        <!-- <nav-header></nav-header> -->
        <div class="zh-table">
            <div class="zh-table-open clear">
                <div class="zh-open-left fl">
                    <div class="open-width" style="width: 150px;" v-if="$store.state.platformInformation">
                        <el-select v-model="school_id" filterable placeholder="来源学校/教育局">
                            <el-option v-for="item in schoolcodeData" :key="item.id" :label="item.name"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </div>
                    <div class="open-width" style="width: 100px;">
                        <el-select v-model="status" filterable placeholder="选择状态">
                            <el-option label="待审核" :value="1"></el-option>
                            <el-option label="已通过" :value="2"></el-option>
                            <el-option label="已拒绝" :value="3"></el-option>
                        </el-select>
                    </div>
                    <div class="open-width">
                        <el-input placeholder="视频名称" v-model="keyword" @keyup.enter.native="search"></el-input>
                    </div>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button type="primary" @click="reset">重置</el-button>
                </div>
                <div class="zh-open-right fr">
                    <el-button type="danger" @click="delAllresource">批量删除</el-button>
                </div>
            </div>
            <div class="zh-table-contents" v-loading="loading.status" :element-loading-text="loading.txt">
                <el-table :data="listData" border max-height="541" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" align="center" width="50" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column prop="name" label="资源名称" align="center" show-overflow-tooltip>
                        <template slot-scope="scope">
                            {{ scope.row.name }}.{{ scope.row.resourceInfo.postfix }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="resourceInfo.category" label="组织架构" align="center" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column prop="resourceInfo.teacher_name" label="上传人" align="center" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column prop="resourceInfo.create_time" label="上传时间" align="center" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column prop="status_txt" label="状态" align="center" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column fixed="right" prop="handle" label="操作" align="center" width="250">
                        <template slot-scope="scope">
                            <template v-if="scope.row.type === 1">
                                <el-button v-if="scope.row.status === 1" @click.stop="viewResource(scope.row)"
                                    type="text">预览</el-button>
                                <!-- <el-button v-if="scope.row.status === 2" type="text" @click.stop="down(scope.row)">下载</el-button> -->
                                <!-- <el-button v-if="scope.row.status === 2" type="text" @click.stop="jumpEdit(scope.row)">编辑</el-button> -->
                                <!-- <el-button v-if="scope.row.status === 2" type="text" @click.stop="pushTop(scope.row)">推上级</el-button> -->
                                <el-button v-if="scope.row.status === 1" type="text"
                                    @click.stop="checkPassTrigger(scope.row)">通过</el-button>
                                <el-button v-if="scope.row.status === 1" type="text"
                                    @click.stop="rejectTrigger(scope.row)">拒绝</el-button>
                                <el-button v-if="scope.row.status !== 1" type="text" class="delete-button"
                                    @click.stop="delTrigger(scope.row)">删除</el-button>
                            </template>
                            <template v-if="scope.row.type === 2">
                                <el-button v-if="scope.row.status === 2" @click.stop="viewResource(scope.row)"
                                    type="text">预览</el-button>
                                <!-- <el-button v-if="scope.row.status === 1" type="text" @click.stop="down(scope.row)">下载</el-button> -->
                                <!-- <el-button v-if="scope.row.status === 1" type="text" @click.stop="jumpEdit(scope.row)">编辑</el-button> -->
                                <!-- <el-button v-if="scope.row.status === 1" type="text" @click.stop="pushTop(scope.row)">推上级</el-button> -->
                                <el-button v-if="scope.row.status === 2" type="text"
                                    @click.stop="checkPassTrigger(scope.row)">通过</el-button>
                                <el-button v-if="scope.row.status === 2" type="text"
                                    @click.stop="cancelTrigger(scope.row)">拒绝</el-button>
                                <el-button v-if="scope.row.status !== 2" type="text" class="delete-button"
                                    @click.stop="delete_confirm(scope.row)">删除</el-button>
                            </template>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="table-pagination" v-show="total_number > 10">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="listParam.page_index" :page-sizes="[10, 20, 30, 40, 50, 100]"
                        :page-size="listParam.page_size" layout="total, sizes, prev, pager, next, jumper"
                        :total="total_number">
                    </el-pagination>
                </div>
            </div>
        </div>
        <transition name="el-fade-in-linear">
            <div class="masking" :class="{ activeLive: isActive }">
                <div class="maskingBox" v-loading="viewLoading.status" :element-loading-text="viewLoading.txt">
                    <div class="masking_h">
                        <span>视频预览</span>
                        <i class="el-icon-close" @click="viewClose"></i>
                    </div>
                    <div class="masking_c">
                        <!-- <nativeVideo v-if="showVideoPlayer" :playParam.sync="playParam">
                            </nativeVideo> -->
                        <dplayerA v-if="showVideoPlayer" :playParam.sync="playParam"></dplayerA>
                    </div>
                </div>
            </div>
        </transition>
        <transition name="el-fade-in-linear" lock-scroll="false">
            <div class="masking" :class="{ activeLive: isPDFActive }">
                <div class="maskingBox">
                    <div class="masking_h">
                        <span>文档预览</span>
                        <i class="el-icon-close" @click="viewPDFClose"></i>
                    </div>
                    <div class="masking-document">
                        <div class="pdf-View">
                            <iframe :src="viwPdfParam.src" frameborder="0" style="width: 100%; height: 100%;"></iframe>
                        </div>
                    </div>
                </div>
            </div>
        </transition>

        <image-viewer v-if="imagePreview.showViewer" :initial-index="imageIndex" :on-close="closeViewer"
            :url-list="imagePreview.previewSrcList">
        </image-viewer>

        <el-dialog title="音频预览" :visible.sync="voiceVisible" width="auto" style="min-width:550px;" top="0"
            custom-class="imgVisible" :close-on-click-modal="false" :before-close="closeAudio">
            <div class="imgViewx">
                <audio id="voicepoauy" controls="controls" :src="voiceViewUrl" controlsList="nodownload" autoplay>
                    Your browser does not support the audio tag.
                </audio>
            </div>
        </el-dialog>
        <!-- bengin -->
        <el-dialog title="拒绝理由" :visible.sync="rejectDescFlag" :close-on-click-modal="false"
            :close-on-press-escape="false" width="40%">
            <div v-text="rejectDesc"></div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="rejectDescFlag = false">取 消</el-button>
                <el-button type="primary" @click="rejectDescFlag = false">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 拒绝理由end -->
        <!-- 拒绝bengin -->
        <el-dialog title="审核拒绝" :visible.sync="rejectWin" :close-on-click-modal="false" :close-on-press-escape="false"
            width="40%">
            <div class="textarea-box">
                <p style="text-align: center" v-if="$store.state.platformInformation">是否拒绝该资源的推送？</p>
                <el-form v-else :model="rejectForm" ref="rejectForm" label-width="80px" class="demo-ruleForm">
                    <el-form-item label="拒绝理由" prop="txt"
                        :rules="[{ required: true, message: '请填写拒绝理由', validator: checkValue }]">
                        <el-input type="textarea" placeholder="在此填写拒绝理由..." v-model="rejectForm.txt" :maxlength="100"
                            required></el-input>
                    </el-form-item>
                </el-form>
                <p class="str-num" v-show="!$store.state.platformInformation">
                    <span v-text="rejectForm.txt.length"></span>/<span class="str-max">100</span>
                </p>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="rejectWinHide">取 消</el-button>
                <el-button type="primary" v-if="cancelType == 1" @click="reject">确 定</el-button>
                <el-button type="primary" v-else @click="rejectRow">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 拒绝end -->
        <!-- 审核通过样式start  -->
        <el-dialog title="审核通过" :visible.sync="checkPassFlag" :close-on-click-modal="false"
            :close-on-press-escape="false" width="33%">
            <div style="text-align: center">请对通过审核的资源进行分类选择</div>
            <div class="resourceBox">
                <p>资源分类：</p>
                <el-select v-model="cate_id" style="width:120px;" filterable placeholder="全部">
                    <!--@change="getVal"-->
                    <el-option v-for="item of resoureKindData" :label="item.name" :value="item.id" :key="item.id">
                    </el-option>
                </el-select>
                <el-button v-if="$store.state.checkLevel" style="margin-left:10px;" type="text"
                    @click="addReskindTrigger()">添加类别</el-button>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="checkPassTips(0)">取 消</el-button>
                <el-button type="primary" v-if="cancelType == 1" @click="checkPassTips(1)">确 定</el-button>
                <el-button type="primary" v-else @click="approve">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 审核通过样式end  -->
        <!-- 添加分类----------------------------------------------------- -->
        <el-dialog title="资源类别" :visible.sync="addReskindFlag" :close-on-click-modal="false"
            :close-on-press-escape="false" @close="handleClosed()" width="30%">
            <p>添加分类：
                <el-input type="text" style="width:220px;" placeholder="输入资源分类，不超过8个字" @keyup.enter.native="addCategory"
                    v-model.trim="addKindvalue" maxlength="8"> </el-input>
                <el-button type="primary" @click="addCategory">添加</el-button>
            </p>
            <p style="padding-bottom:20px;">分类管理:
                <el-tag size="mini" v-for="item in resoureKindData" :key="item.id" @close.stop="delCategory(item.id)"
                    style="margin-top:5px;margin-right:5px;" closable>{{ item.name }} </el-tag>
            </p>
        </el-dialog>
        <!-- 添加分类-------------------------------------------------------------------- -->
    </div>
</template>
<script>
// import nativeVideo from '../../public/nativeVideo'
import dplayerA from "@/components/public/dplayerA.vue";

export default {
    data() {
        return {
            cancelType: '',
            userId: JSON.parse(sessionStorage.getItem('user_info_str')).id,
            check_rolebaseid: '',
            school_id: '',
            schoolcodeData: [], /**存放学校教育局列表 */
            myid: '',
            addKindvalue: '',
            addReskindFlag: false,
            cate_id: 0,
            // cate_name: '',
            resoureKindData: [],
            checkPassFlag: false,
            ids: [],/*存放被选中的资源列表 */
            types: [],
            rules: {
                name: [
                    { required: true, message: '请输入资源名称', trigger: 'blur' },
                    { pattern: this.rules.spaceKey.reg, message: this.rules.spaceKey.msg, trigger: 'blur' },
                    { min: 1, max: 50, message: '长度在 1 到 50 个字符' }
                ],

            },
            names: '',
            imagePreview: {
                showViewer: false,
                previewSrcList: []
            },
            platform_id: "",
            keyword: "",
            platformList: [],
            loading: {
                status: false,
                txt: "获取数据..."
            },
            total_number: 0,
            listData: [],
            listParam: {
                type: 1,
                platform_id: 0,
                keyword: "",
                status: "",
                page_index: 1,
                page_size: 10
            },
            status: '',
            rejectWin: false /*拒绝弹窗 */,
            rejectForm: {
                txt: "" /*拒绝理由填写 */
            },
            rejectObj: null /*拒绝对象 */,
            showVideoPlayer: false,
            playParam: { play_url: '' },
            rejectDescFlag: false,
            rejectDesc: "",
            isActive: true,
            isPDFActive: true,
            viwPdfParam: {
                src: '',
                loadedRatio: 0,
                page: 1,
                numPages: 0,
                rotate: 0,
            },
            imgVisible: false,
            imgViewUrl: '',
            voiceVisible: false,
            voiceViewUrl: '',
            viewLoading: {
                status: false,
                txt: '加载数据...'
            },
            platform: '',
            classTypeArr: {
                1: '课件', 2: '视频', 3: '教案', 4: '试卷', 5: '其他', 0: '未知'
            },
            statusArr: {
                2: '未审核',
                3: '未通过',
                1: '已通过'
            },
        };
    },
    created() {
        this.getList();
        this.getSourceKind();
        this.get_schoolcode();
        this.platform_parent();
        this.getUserInfo();
    },
    computed: {
        imageIndex() {
            return this.imagePreview.previewSrcList.indexOf(this.imgViewUrl);
        }
    },
    methods: {
        /**单机 */
        getClassType(val) {
            return this.classTypeArr[parseInt(val)]
        },
        getStatus(val) {
            return this.statusArr[parseInt(val)]
        },
        /**单机 */
        // 获取用户身份 /api/login/login
        getUserInfo() {
            let params = {
                check_rolebaseid: this.userId
            }
            let success = res => {
                // console.log(res.data, 110)
                this.check_rolebaseid = res.data.userinfo.check_rolebaseid
            }
            this.$ajax.get('/api/login/login', { params, func: { success } })
        },
        /**
         * 关闭音频播放
         */
        closeAudio() {
            this.voiceVisible = false;
            document.getElementById("voicepoauy").pause();
        },
        checkValue(rule, value, callback) {
            if (!checkSpace(value)) {
                callback(new Error("请输入有效值"));
            } else {
                callback();
            }
        },
        get_schoolcode() { /*获取学校教育局 */
            let params = {
                app_code: sessionStorage.getItem('CheckSchoolAppCode')
            }
            let success = res => {
                // console.log(res, 'pppp')
                this.schoolcodeData = res.data
            }
            this.$ajax.get('api/group/get_platform_org', { params, func: { success } })
        },
        get_canseeposition() {
            const success = res => {
                this.platformList = res.data.data;
            };
            this.$ajax.get("api/level/get_canseeposition_school", {
                params: {},
                func: { success: success }
            });
        },
        getList() {
            this.loading.status = true;
            const success = res => {
                this.loading.status = false;
                this.listData = res.data.data;
                console.log(JSON.parse(JSON.stringify(res.data.data)), 99)
                this.total_number = res.data.data_sum;
            };
            if (this.$store.state.checkLevel) {
                this.$ajax.get('api/resource/resource_pushed_receive', { params: this.listParam, func: { success } })
            } else {
                this.listParam.data_type = 2,
                    this.listParam.authonity = [1],
                    this.$ajax.get("api/resource/resource", {
                        params: this.listParam,
                        func: { success: success }
                    });
            }
        },
        search() {
            this.listParam.school_id = this.school_id;
            this.listParam.status = this.status;
            this.listParam.platform_id = this.platform_id;
            this.listParam.keyword = this.keyword;
            this.listParam.page_index = 1;
            this.getList();
        },
        reset() {
            this.school_id = ''
            this.platform_id = "";
            this.keyword = "";
            this.status = '';
            this.listParam = {
                school_id: '',
                type: 1,
                platform_id: 0,
                keyword: "",
                status: "",
                page_index: 1,
                page_size: 10
            };
            this.getList();
        },
        handleSizeChange(size) {
            this.listParam.page_size = size;
            this.getList();
        },
        handleCurrentChange(page) {
            this.listParam.page_index = page;
            this.getList();
        },
        pass(id) {
            /*批准*/
            let params = {
                id: id,
            };
            const success = res => {
                console.log(res)
                this.$message.success(res.msg);
                this.getList();
            };
            const fail = res => {
                console.log(res)
            }
            if (this.$store.state.checkLevel) {
                this.$ajax.post('api/resource/resource_pushed_receive', params, { func: { success, fail } })
            } else {
                this.$ajax.post("api/level/approve_pushed_receive", params, { func: { success, fail } });
            }
        },
        passTrigger(data) {
            /*批准提示 */
            let tipsTxt = `确定批准${data.name}通过审核吗？`;

            this.$confirm(tipsTxt, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                this.pass(data.id);
            }).catch(() => {
                this.$message({
                    type: "info",
                    message: "已取消批准"
                });
            });
        },
        checkPassTrigger(obj) { /**触发审核弹窗 */
            console.log(obj)
            this.myid = obj.id
            this.cate_name = obj.resourceInfo.cate_name
            this.checkPassFlag = true
            this.cancelType = obj.type
        },
        approve() {
            let params = {
                id: this.myid,
                cate_id: this.cate_id,
                status: 1,
                comment: '',
            }
            let success = (data => {
                this.$message.success(data.msg);
                this.checkPassFlag = false
                this.rejectWinHide();
                this.getList();
            });
            this.$ajax.post('api/resource/approve', params, { func: { success: success } })
        },

        rejectTrigger(data) {
            /*拒绝弹窗 */
            console.log(data)
            this.cancelType = data.type
            this.rejectWin = true;
            this.rejectObj = data;
        },
        rejectWinHide() {
            /*隐藏拒绝弹窗 */
            this.rejectWin = false;
            this.rejectObj = null;
            this.rejectForm.txt = "";
        },
        reject() {
            /*拒绝 */
            let params = {
                id: this.rejectObj.id,
                comment: this.rejectForm.txt
            };
            const success = res => {
                this.$message.success(res.msg);
                this.rejectWinHide();
                this.getList();
            };
            if (this.$store.state.checkLevel) {
                if (this.$store.state.platformInformation) {
                    this.$ajax.put("api/resource/resource_pushed_receive", params, {
                        func: { success: success }
                    });
                } else {
                    this.$refs[`rejectForm`].validate(valid => {
                        if (valid) {
                            this.$ajax.put("api/resource/resource_pushed_receive", params, {
                                func: { success: success }
                            });
                        } else {
                            return;
                        }
                    });
                }
            } else {
                this.$refs[`rejectForm`].validate(valid => {
                    if (valid) {
                        this.$ajax.put("api/level/refuse_pushed_receive", params, {
                            func: { success: success }
                        });
                    } else {
                        return;
                    }
                });
            }
        },
        cancelTrigger(obj) { //  type == 2 时本地资源上传的审核 拒绝
            this.cancelType = obj.type
            this.rejectWin = true;
            this.rejectObj = obj;
            console.log(obj)
        },
        rejectRow() {
            /*拒绝 */
            let params = {
                id: this.rejectObj.id,
                status: 3,
                // comment: this.rejectForm.txt
            };
            if (this.$store.state.platformInformation) {
                let success = res => {
                    this.$message.success(res.msg);
                    this.checkPassFlag = false
                    this.rejectWinHide();
                    this.getList();
                }
                this.$ajax.post('api/resource/approve', params, { func: { success: success } })
            } else {
                this.$refs[`rejectForm`].validate(valid => {
                    if (valid) {
                        let success = res => {
                            this.$message.success(res.msg);
                            this.checkPassFlag = false
                            this.rejectWinHide();
                            this.getList();
                        }
                        this.$ajax.post('api/resource/approve', params, { func: { success: success } })
                    } else {
                        return;
                    }
                });
            }
        },
        del(id) {
            let params = {
                id: id,
            };
            const success = res => {
                this.$message.success(res.msg);

                if (this.listData.length - 1 === 0) {
                    if (this.listParam.page_index > 1) {
                        this.listParam.page_index--;
                    } else {
                        this.listParam.page_index = 1;
                    }
                }

                this.getList();
            };
            if (this.$store.state.checkLevel) {
                this.$ajax.delete("api/resource/resource_pushed_receive", {
                    params: params,
                    func: { success: success }
                });
            } else {
                this.$ajax.delete("api/level/delete_pushed_receive", {
                    params: params,
                    func: { success: success }
                });
            }
        },
        delTrigger(data) {
            /*删除提示 */
            let tipsTxt = `确认删除${data.name}吗？`;
            this.$confirm(tipsTxt, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                this.del(data.id);
            }).catch(() => {
                this.$message({
                    type: "info",
                    message: "已取消删除"
                });
            });
        },
        // type == 2 本地推送的资源删除
        delete_confirm(obj) {
            let yes = (data => {
                this.delete(obj.id, 0);
            })
            let cancel = (data => { })
            this.e_confirm({ yes: yes, cancel: cancel, txt: '确定将 ' + obj.name + ' 删除吗？' });

        },
        delete(id, status) {
            let success = (data => {
                this.$message.success(data.msg);
                if (this.listData.length - 1 === 0) {
                    if (this.listParam.page > 1) {
                        this.listParam.page--;
                    } else {
                        this.listParam.page = 1;
                    }
                }
                this.getList();
            });
            let params = {
                id: id,
                examine: status
            }
            this.$ajax.put('api/resource/resource', params, { func: { success: success } })
        },
        /**
         * 新添加1111111111111111111111111111111
         */
        handleSelectionChange(val) { /**选框状态 */
            this.ids = [];
            this.types = [];
            if (val.length > 0) {
                val.forEach(item => {
                    if (item.type === 1) {
                        this.ids.push(item.id);
                    } else {
                        this.types.push(item.id);
                    }
                })
            }
            console.log(this.types, this.ids)
        },
        delAllresource() { /**批量删除 */
            if (this.ids.length <= 0 && this.types.length <= 0) {
                this.$message.warning('请选择要删除的选项');
                return false;
            }
            const cancel = (res => { })
            const yes = (res => {
                this.listData.forEach((item) => {
                    if (item.type === 1) {
                        this.ids.forEach((itm) => {
                            if (item.id == itm) {
                                this.del(itm)
                            }
                        })
                    }
                    if (item.type === 2) {
                        this.types.forEach(ite => {
                            if (item.id == ite) {
                                this.delete(ite, 0)
                            }
                        })
                    }
                })
            })
            this.e_confirm({ yes, cancel, txt: "确定要删除选中的资源吗？" });
        },
        down(obj) {
            var form = document.createElement("form");
            var type = 1;
            form.action = this.BASE_URL + '/index/resource/resourcedownload';
            form.method = 'post';
            form.style.display = "none";

            var opt_id = document.createElement("textarea");
            opt_id.name = 'id';
            opt_id.value = obj.resourceInfo.id;
            form.appendChild(opt_id);
            var opt_type = document.createElement("textarea");
            opt_type.name = 'type';
            opt_type.value = type;
            form.appendChild(opt_type);
            document.body.appendChild(form);
            form.submit();
            document.body.removeChild(form);
        },
        // getVal(val){ // 获取当前选中项，
        //     // this.cate_id = val // 把获取到的分类id 给
        //     console.log(val)
        //     this.cate_id = val
        // },
        checkPassTips() { // 通过审核
            if (!arguments[0]) {
                this.checkPassFlag = false
                return
            }
            let success = res => {
                this.$message.success(res.msg)
                this.checkPassFlag = false
                this.getList();
            }
            let params = {
                id: this.myid,
                cate_id: this.cate_id
            }
            this.$ajax.post('api/resource/resource_pushed_receive', params, { func: { success } })
        },
        /**获取资源类别 */
        getSourceKind() {
            let success = res => {
                console.log(res.data)
                this.resoureKindData = res.data
                this.resoureKindData.unshift({ id: 0, name: '全部' })
            }
            this.$ajax.get('api/resource/resource_cate', { func: { success } })
        },
        addReskindTrigger() { // 弹窗状态
            this.addReskindFlag = true
        },
        /**添加资源类别 */
        addCategory() {
            if (this.addKindvalue == '') {
                this.$message.error('内容不能为空')
                return
            }
            if (this.resoureKindData.some(i => { return i.name == this.addKindvalue })) {
                this.$message.error('已有该类别')
                return
            }
            let params = {
                name: this.addKindvalue
            }
            let success = res => {
                this.$message.success(res.msg);
                this.addKindvalue = '';
                this.getSourceKind()
            }
            let fail = data => {
                this.$message.error(res.msg);
                this.addKindvalue = '';
            }
            this.$ajax.post('api/resource/resource_cate', params, { func: { success, fail } })
        },
        /**删除资源类别--- */
        delCategory(id) {
            let params = {
                id: id,
            }
            let success = res => {
                this.$message.success(res.msg);
                this.getSourceKind()
            }
            this.$ajax.delete('api/resource/resource_cate', { params, func: { success } })
        },
        handleClosed() {
            this.addKindvalue = ''
        },
        platform_parent() {/*获取可推送上级 */
            const success = res => {
                if (!is_empty(res.data)) {
                    this.platform = res.data;
                    this.pid = res.data.id;
                }
            }
            this.$ajax.get('api/level/platform_parent', { params: {}, func: { success: success } })
        },
        pushTop(data) { /**推上级 */
            let title = `是否要将资源推送至${this.platform.name}？（需经过审核）`;
            this.$confirm(title, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.pushUp(data.new_res_id);
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消推送'
                });
            });
        },
        pushUp(id) {  /**推上级 */
            let params = {
                resource_id: id,
            }
            const success = res => {
                this.$message.success(res.msg)
                this.ids = [];
                this.getList();
            }
            this.$ajax.post("api/resource/resource_push", params, { func: { success: success } });
        },
        jumpEdit(obj) {
            console.log(obj)
            this.$router.push('/resources/resource/resource-edit/' + obj.new_res_id);
        },
        /**
         * 新添加1111111111111111111111111111111
         */
        pdfPageChange(val) {
            this.viwPdfParam.page = val;
        },
        error: function (err) {
            //this.$message.error('读取文件失败');
        },

        //资源预览转发
        viewResource(obj) {
            console.log(obj, 111)
            this.viewLoading.status = true;
            if (!this.$store.state.checkLevel) {
                this.imgViewUrl = undefined;
            }
            //视频预览
            if (parseInt(obj.resourceInfo.file_type) === 6) {
                this.isActive = false
            }
            //图片预览
            else if (parseInt(obj.resourceInfo.file_type) === 3) {
                this.imgVisible = true;
            }
            //文档预览
            else if (parseInt(obj.resourceInfo.file_type) === 1) {
                // this.isPDFActive = false
            }
            //音频预览
            else if (parseInt(obj.resourceInfo.file_type) === 5) {
                this.voiceVisible = true;
                this.voiceView(obj)
            } else {
                this.$message.warning("不支持预览的资源类型")
                return false;
            }
            let success = (data => {
                var result = data.data;
                //视频预览
                if (parseInt(result.file_type) === 6) {
                    this.videoView(result.path);
                }
                //图片预览
                else if (parseInt(result.file_type) === 3) {
                    this.imgView(result.path);
                }
                //文档预览
                else if (parseInt(result.file_type) === 1) {
                    this.isPDFActive = false
                    this.pdfView(result.path);
                }
                //音频预览
                else if (parseInt(result.file_type) === 5) {
                    this.voiceView(result.path)
                } else {
                    this.$message.warning("不支持预览的资源类型")
                }
            })
            let fail = (data => {
                this.isPDFActive = true
                this.viewLoading.status = false;
                this.$message.error(data.msg)
            })
            if (!this.$store.state.checkLevel) {
                this.$ajax.get('api/resource/view_info', { params: { id: obj.id, is_video: obj.is_video }, func: { success: success, fail: fail } })
            } else {
                this.$ajax.get('api/resource/view_info', { params: { id: obj.old_res_id }, func: { success: success, fail: fail } })
            }
        },
        voiceView(url) {
            this.voiceViewUrl = url;
            document.getElementById("voicepoauy").load();
        },
        imgView(url) {
            this.imgViewUrl = url;
            this.imagePreview.showViewer = true;
            this.imagePreview.previewSrcList = [url];
        },
        closeViewer() {
            this.imagePreview.showViewer = false;
        },
        //pdf预览
        pdfView(url) {
            this.viwPdfParam.src = (url)
            // this.viwPdfParam.src =  pdf.createLoadingTask(url)
        },
        viewPDFClose() {
            this.isPDFActive = true
        },
        //关闭视频预览
        viewClose() {
            this.showVideoPlayer = false;
            this.isActive = true

        },
        //视频预览
        videoView(url) {
            this.showVideoPlayer = true;
            this.playParam.play_url = url;
        },
        checkReject(data) {
            this.rejectDescFlag = true;
            this.rejectDesc = data.comment;
        }
    },
    components: {
        // nativeVideo
        // pdf
        dplayerA,
    }
};
</script>
<style lang="scss">
.teaching-push-check {
    .resourceBox {
        width: 100%;
        height: 33px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 15px 0 25px 0;
    }

    .textarea-box {
        position: relative;

        .el-textarea__inner {
            min-height: 120px !important;
            resize: none;
        }

        .str-num {
            position: absolute;
            padding: 0;
            margin: 0;
            left: 0;
            bottom: 5px;
            right: 15px;
            text-align: right;

            .str-max {
                color: #ddd;
            }
        }
    }

    .el-table__body-wrapper table tbody {
        td:nth-child(8) {
            padding: 0;
        }
    }

    .masking {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        // height: 100%;
        transition: .5s;
        background: rgba(0, 0, 0, .3);
        z-index: 4;

        .maskingBox {
            position: absolute;
            top: 15%;
            left: 50%;
            width: 800px;
            margin-left: -400px;
            background: #fff;
        }

        .masking_h {
            padding: 10px 15px;
            background: #348EFC;
            text-align: center;
            text-align-last: justify;

            >span,
            >i {
                font-size: 16px;
                text-align-last: initial;
                display: inline-block;
                vertical-align: middle;
                color: #fff;
            }

            >i {
                cursor: pointer;
            }
        }

    }

    // .masking_c {
    //     .el-pagination {
    //         padding-bottom: 20px;
    //     }
    // }
	.masking_c {
		padding: 15px;
        height: 450px;
	}

    .activeLive {
        opacity: 0;
        visibility: hidden;
    }

    .imgVisible {
        display: inline-block;
        vertical-align: middle;
        background: none;
        text-align: left;
        min-width: 550px;
        min-height: 550px;
        background: rgba(109, 116, 125, 0.78);
        margin: 0;

        .el-dialog__header {
            // display: none;
        }

        .el-dialog__body {
            text-align: center;
            padding: 0;

            img {
                max-width: 100%;
            }
        }
    }

    .picture-preview {
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;

        .el-dialog {
            margin: 0;
            margin-top: 0 !important;
            width: 70vw;
            height: 70vh;
            max-width: 1200px;
            max-height: 900px;
            overflow: hidden;

            .el-dialog__body {
                padding: 20px 0;
                width: 100%;
                height: calc(100% - 40px);
                box-sizing: border-box;

                div {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    padding: 0 40px;
                    width: 100%;
                    height: 100%;
                    text-align: center;
                    overflow-y: auto;
                    box-sizing: border-box;

                    img {
                        width: 100%;
                        height: 100%;
                        max-width: 100%;
                        max-height: 100%;
                        object-fit: contain;
                    }
                }
            }
        }
    }
}
</style>

